home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -screenplay- / shareware / warpquake / warpquakesrc / sys_amiga.c < prev    next >
C/C++ Source or Header  |  2000-02-29  |  7KB  |  358 lines

  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  12.  
  13. See the GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. */
  20.  
  21. const char amigaversion[] = "$VER: WarpQuake 0.4 (26.1.100)\n";
  22.  
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25.  
  26. #include <utility/tagitem.h>
  27. #include <exec/exec.h>
  28. #include <exec/types.h>
  29. #include <dos/exall.h>
  30. #include <dos/dos.h>
  31. #include <powerup/ppcproto/dos.h>
  32. #include <powerup/ppcproto/exec.h>
  33. #include <powerpc/powerpc.h>
  34. #include <powerpc/powerpc_protos.h>
  35.  
  36. #include "quakedef.h"
  37. #include "errno.h"
  38.  
  39. #include "amiga_timer.h"
  40.  
  41. qboolean isDedicated = FALSE;
  42.  
  43. static int cpu_type;
  44. static int bus_clock;
  45. static int bus_MHz;
  46. static double clocks2secs;
  47.  
  48. extern struct Mode_Screen *msptr;
  49.  
  50. void File_Shutdown (void);
  51.  
  52. /*
  53. ===============================================================================
  54.  
  55. FILE IO
  56.  
  57. ===============================================================================
  58. */
  59.  
  60. #define    MAX_HANDLES        10
  61. BPTR    sys_handles[MAX_HANDLES];
  62.  
  63. int        findhandle (void)
  64. {
  65.     int        i;
  66.     
  67.     for (i=1 ; i<MAX_HANDLES ; i++)
  68.         if (!sys_handles[i])
  69.             return i;
  70.     Sys_Error ("out of handles");
  71.     return -1;
  72. }
  73.  
  74. /*
  75. ================
  76. filelength
  77. ================
  78. */
  79. int filelength (BPTR f)
  80. {
  81.     LONG        pos;
  82.     LONG        end;
  83.  
  84.     pos = Seek (f, 0, OFFSET_END);
  85.     end = Seek (f, pos, OFFSET_BEGINNING);
  86.  
  87.     return (int) end;
  88. }
  89.  
  90. int Sys_FileOpenRead (char *path, int *hndl)
  91. {
  92.     BPTR    f;
  93.     int        i;
  94.     
  95.     i = findhandle ();
  96.  
  97.     printf ("Opening '%s' for read\n", path);
  98.     f = Open(path, MODE_OLDFILE);
  99.     if (!f)
  100.     {
  101.         *hndl = -1;
  102.         return -1;
  103.     }
  104.     sys_handles[i] = f;
  105.     *hndl = i;
  106.     
  107.     return filelength(f);
  108. }
  109.  
  110. int Sys_FileOpenWrite (char *path)
  111. {
  112.     BPTR    f;
  113.     int        i;
  114.     
  115.     i = findhandle ();
  116.  
  117.     printf ("Opening '%s' for write\n", path);
  118.     f = Open(path, MODE_NEWFILE);
  119.     if (!f)
  120.         Sys_Error ("Error opening %s: %s", path,strerror(errno));
  121.     sys_handles[i] = f;
  122.     
  123.     return i;
  124. }
  125.  
  126. void Sys_FileClose (int handle)
  127. {
  128. //    printf("Sys_FileClose() %i\n", handle);
  129.     Close (sys_handles[handle]);
  130.     sys_handles[handle] = NULL;
  131. }
  132.  
  133. void Sys_FileSeek (int handle, int position)
  134. {
  135.     /* printf ("%d: Seeking to %d\n", handle, position); */
  136.     if (Seek (sys_handles[handle], position, OFFSET_BEGINNING) == -1)
  137.         Sys_Error ("Error in Seek()");
  138. }
  139.  
  140. int Sys_FileRead (int handle, void *dest, int count)
  141. {
  142.     /* printf ("%d: Reading %d to %08x\n", handle, count, dest); */
  143.     return (int)Read (sys_handles[handle], dest, count);
  144. }
  145.  
  146. int Sys_FileWrite (int handle, void *data, int count)
  147. {
  148.     return (int)Write (sys_handles[handle], data, count);
  149. }
  150.  
  151. int    Sys_FileTime (char *path)
  152. {
  153.     BPTR    f;
  154.     
  155.     f = Open(path, MODE_OLDFILE);
  156.     if (f)
  157.     {
  158.         Close(f);
  159.         return 1;
  160.     }
  161.     
  162.     return -1;
  163. }
  164.  
  165. void Sys_mkdir (char *path)
  166. {
  167. }
  168.  
  169.  
  170. /*
  171. ===============================================================================
  172.  
  173. SYSTEM IO
  174.  
  175. ===============================================================================
  176. */
  177.  
  178. void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
  179. {
  180. }
  181.  
  182.  
  183. void Sys_DebugLog(char *file, char *fmt, ...)
  184. {
  185. }
  186.  
  187. void Sys_Error (char *error, ...)
  188. {
  189.     va_list        argptr;
  190.  
  191.     printf ("Sys_Error: ");    
  192.     va_start (argptr,error);
  193.     vprintf (error,argptr);
  194.     va_end (argptr);
  195.     printf ("\n");
  196.  
  197.     Host_Shutdown();
  198.     File_Shutdown();
  199.     exit (20);
  200. }
  201.  
  202. void Sys_Printf (char *fmt, ...)
  203. {
  204.     va_list        argptr;
  205.     
  206.     va_start (argptr,fmt);
  207.     if (!con_initialized)
  208.       vprintf (fmt,argptr);
  209.     va_end (argptr);
  210. }
  211.  
  212. void Sys_Quit (void)
  213. {
  214.     Host_Shutdown();
  215.     File_Shutdown();
  216.     exit (0);
  217. }
  218.  
  219. void File_Shutdown (void)
  220. {
  221.     int i;
  222.  
  223.     for (i=1; i<MAX_HANDLES ; i++)
  224.     {
  225.         if (sys_handles[i])
  226.             Sys_FileClose (i);
  227.     }
  228. }
  229.  
  230. double Sys_FloatTime (void)
  231. {
  232.   unsigned int clock[2];
  233.  
  234.   ppctimer (clock);
  235.   return (((double)clock[0]) * 4294967296.0 + (double)clock[1]) *
  236.          clocks2secs;
  237. }
  238.  
  239. char *Sys_ConsoleInput (void)
  240. {
  241.     return NULL;
  242. }
  243.  
  244. void Sys_Sleep (void)
  245. {
  246. }
  247.  
  248. /*
  249. void Sys_SendKeyEvents (void)
  250. {
  251. }
  252. */
  253.  
  254. void Sys_HighFPPrecision (void)
  255. {
  256. }
  257.  
  258. void Sys_LowFPPrecision (void)
  259. {
  260. }
  261.  
  262. //=============================================================================
  263.  
  264. int main (int argc, char **argv)
  265. {
  266.   int j;
  267.     int bat;
  268.   double time, oldtime, newtime;
  269.   quakeparms_t parms;
  270.  
  271.     msptr = NULL;
  272.  
  273.   memset (&parms, 0, sizeof(parms));
  274.  
  275.   COM_InitArgv (argc, argv);
  276.  
  277.   parms.memsize = 8*1024*1024;
  278.   j = COM_CheckParm("-mem");
  279.   if (j)
  280.     parms.memsize = (int) (Q_atof(com_argv[j+1]) * 1024 * 1024);
  281.   if ((parms.membase = malloc (parms.memsize)) == NULL)
  282.     Sys_Error ("Can't allocate %d bytes", parms.memsize);
  283.   parms.basedir = "PROGDIR:";
  284.   parms.cachedir = "";
  285.  
  286.   parms.argc = com_argc;
  287.   parms.argv = com_argv;
  288.  
  289.     bat = COM_CheckParm("-bat");
  290.     if (bat)
  291.         ChangeMMU (CHMMU_BAT);
  292.  
  293.   {
  294.     struct TagItem ti_cputype = {GETINFO_CPU, 0};
  295.     struct TagItem ti_cpuclock = {GETINFO_CPUCLOCK, 0};
  296.     struct TagItem ti_busclock = {GETINFO_BUSCLOCK, 0};
  297.  
  298.     GetInfo (&ti_cputype);
  299.     cpu_type = ti_cputype.ti_Data;
  300.     switch (cpu_type) {
  301.       case CPUF_603:
  302.         printf ("\nCPU is PPC603 ");
  303.         break;
  304.       case CPUF_604:
  305.         printf ("\nCPU is PPC604 ");
  306.         break;
  307.       case CPUF_603E:
  308.         printf ("\nCPU is PPC603e ");
  309.         break;
  310.       case CPUF_604E:
  311.         printf ("\nCPU is PPC604e ");
  312.         break;
  313.       case CPUF_620:
  314.         printf ("\nCPU is PPC620 ");
  315.         break;
  316.       default:
  317.         printf ("\nCPU is PPC ");
  318.         break;
  319.     }
  320.  
  321.     GetInfo (&ti_cpuclock);
  322.     bus_clock = ti_cpuclock.ti_Data;
  323.     printf ("running at %d MHz\n", bus_clock / 1000000);
  324.  
  325.     GetInfo (&ti_busclock);
  326.     bus_clock = ti_busclock.ti_Data;
  327.     bus_MHz = bus_clock / 1000000;
  328.     printf("Bus clock is %d MHz.\n\n", bus_MHz);
  329.  
  330.     clocks2secs = 4.0 / bus_clock;
  331.  
  332.   }
  333.  
  334. //    printf ("Host_Init\n");
  335.     Host_Init (&parms);
  336.  
  337.     Host_Frame (0.1);
  338.  
  339.     oldtime = Sys_FloatTime ();
  340.     while (1)
  341.     {
  342.         newtime = Sys_FloatTime ();
  343.         time = newtime - oldtime;
  344.  
  345.         if (time < 0.0)
  346.             printf ("Negative time = %f!!\n", time);
  347.  
  348.         if (cls.state == ca_dedicated && (time<sys_ticrate.value))
  349.             continue;
  350.  
  351.         Host_Frame ((float)time);
  352.  
  353.         oldtime = newtime;
  354.     }
  355. }
  356.  
  357. /**********************************************************************/
  358.